/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ServerForma.java
 *
 * Created on 11.03.2010., 22.30.29
 */

package server;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.ListModel;
import javax.swing.table.DefaultTableModel;
import model.Korisnik;

/**
 *
 * @author Dejan
 */
public class ServerForma extends javax.swing.JFrame {
   
   List<Korisnik> ko;
   
    private DefaultListModel model;
 static Server s;
    /** Creates new form ServerForma */
    public ServerForma() {
        initComponents();
        //ko=new ArrayList<Korisnik>();
        //jlKorisnici.
         
         napraviListu();
         
//         jlKorisnici.setModel((ListModel) s.getKh());
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jtaOutput = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jtStart = new javax.swing.JToggleButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jlKorisnici = new javax.swing.JList();
        jbIskljuci = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jtaOutput.setColumns(20);
        jtaOutput.setRows(5);
        jScrollPane1.setViewportView(jtaOutput);

        jLabel1.setText("izvestaj:");

        jtStart.setText("pokreni server");
        jtStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtStartActionPerformed(evt);
            }
        });

        jlKorisnici.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(jlKorisnici);

        jbIskljuci.setText("isk");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addComponent(jLabel1))
                            .addComponent(jtStart))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(132, 132, 132)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(213, Short.MAX_VALUE)
                .addComponent(jbIskljuci, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(124, 124, 124))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(jbIskljuci)
                .addGap(76, 76, 76)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jtStart)
                        .addGap(29, 29, 29))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtStartActionPerformed

        osveziListu();
    }//GEN-LAST:event_jtStartActionPerformed

    /**
    * @param args the command line arguments
    */

    public void napraviListu(){

    model = new DefaultListModel(
        );
        jlKorisnici.setModel(model);


    }

    public void osveziListu(){
        for(KlijentHook k:s.getKh()){
            model.addElement(k.getId());


        }
        jlKorisnici.setModel(model);

    }


    public static void main(String args[]) {

 s= new Server();

       
                new ServerForma().setVisible(true);

         s.pokreni();
              
          

           
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbIskljuci;
    private javax.swing.JList jlKorisnici;
    private javax.swing.JToggleButton jtStart;
    private javax.swing.JTextArea jtaOutput;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the jtaOutput
     */
    public javax.swing.JTextArea getJtaOutput() {
        return jtaOutput;
    }

    /**
     * @param jtaOutput the jtaOutput to set
     */
    public void setJtaOutputText(String o) {
        this.jtaOutput.append(o);
    }

}
